package com.prs.crm.action.project.flow;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.ui.PaginationSupport;

import com.prs.crm.action.FlowAction;
import com.prs.crm.context.AppContext;
import com.prs.crm.domain.project.Project;
import com.prs.crm.domain.project.Task;
import com.prs.crm.service.project.ProjectService;
import com.prs.crm.service.project.TaskService;

public class ProjectFlowAction extends FlowAction<Project>{
	
	private static final long serialVersionUID = 1L;
	
	private ProjectService projectService;
	
	private TaskService taskService;
	
	private Project project;
	
	private Task task;
	
	private PaginationSupport pagination;

	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}

	public ProjectService getProjectService() {
		return projectService;
	}

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public TaskService getTaskService() {
		return taskService;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public Project getProject() {
		return project;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public Task getTask() {
		return task;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public PaginationSupport getPagination() {
		return pagination;
	}
	

	@Action("listProjectFlow")
	public String execute()
	{
		pagination = this.getPaginationHelper().prepare(pagination);
		pagination= this.getProjectService().listFlowTask(Project.class,pagination, 
				AppContext.getAccountContext().currentUser());
		return SUCCESS;
	}
	
	@Action("editProjectFlowTask")
	public String edit()
	{
		displayEndNodes();
		this.setTask(this.getTaskService().findRootTask(project));
		return SUCCESS;
	}

	@Action(value="submitProjectFlowTask",results={@Result(name="success",type="redirect",location="listProjectFlow")})
	public String submitTask()
	{
		this.getProjectService().execute(getNode(), getDetail(), project
				,AppContext.getAccountContext().currentUser());
		return SUCCESS;
	}
}
